﻿<form action="<{if $form_url}><{$form_url}><{else}><{link app=b2c ctl=site_cart act=addToCart arg0='goods'}><{/if}>" method="post"
  <{if $setting.buytarget == 2}> target="_blank_cart"<{elseif $setting.buytarget == 3}> target="_dialog_minicart"<{/if}>
  gnotify="<{link app=b2c ctl=site_product act=gnotify}>">
  <div class="dialog-specbox" id='dialog-spec'>
    <div class="spec-pic">
      <{if $product.udfimg == 'true'}>
      <{assign var="gimage" value=$goods.thumbnail_pic}>
      <{else}>
      <{assign var="gimage" value=$goods.image_default_id|default:$defaultImage}>
      <{/if}>

      <img src="<{$gimage|storager:'s'}>"  width="78" height="82" >
      <q><{t}>价格<{/t}>: <span class="font-red font13px fontbold" updateSpec='updateprice'><{$goods.current_price|cur_odr:$order.currency}></span></q>
    </div>
    <div class="dialog-specauto">
      <div class="spec_name">
        <{$goodshtml.name}>
      </div>
      <div class="dialog-content">
        <{$goodshtml.spec}>
        <input name="goods[goods_id]"  value="<{$goods.goods_id}>" type="hidden" />
        <input name="goods[product_id]" updateSpec="updatepid" value="" type="hidden" />
        <input name="goods[pmt_id]"  value="" type="hidden" />
        <input name="goods[num]" value="1" type="hidden" />
        <{if !$goods.nostore_sell}>
        <span class='goods-store' style="display:none"  updateSpec='text_store'><{$goods.store}></span>
        <{/if}>
        <div class="clear"></div>
      </div>
    </div>
    <div style="clear:both" updateSpec="stockout" class="buybtn">
      <{$goodshtml.button}>
    </div>
  </div>
</form>

<script>
  (function(){

    var spec_update=new Goods_spec($('dialog-spec'),{height:15});

    Goods_spec._selectedUpdate['stockout']=function(el,v,pid,pdata){
      el.retrieve('default:callback',function(){
        var storeBtn=spec_update.contains.getElement('.goods-store'),store,
        specBtn=spec_update.contains.getElement('.small-specbtn');

        if(storeBtn&&storeBtn.get('text')==='0')
        return specBtn.addClass('stockout');
        specBtn.removeClass('stockout');
      })();
    }

    if(spec_update.contains.getElement('.nostore'))
    spec_update.contains.getElement('.nostore').addEvent('click',function(){
      var backup = this.form.action;
      this.form.action=this.form.get('gnotify');
      this.form.submit();
      this.form.action = backup;
    });

    //默认选中
    spec_update.specItems.each(function(si){
      var specs=si.getElements('a[specvid]');
      var specBtn = specs.filter(function(sp){
        return (!sp.hasClass('selected')&&!sp.hasClass('lock'));
      })[0];
      specBtn && specBtn.fireEvent('click',{stop:function(){}});
    });
  })();
</script>
